<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>pureftp部署和优化 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>pureftp部署和优化</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/FTP/">FTP</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FTP 是 File Transfer Protocol （文件传输协议）的英文简称，而中文简称为“文传协议”用于 Internet 上的控制文件的双向传输。同时，它也是一个应用程序（Applocation）用户可以通过它把自己的 PC 机与世界各地所有运行 FTP 协议的服务器相连，访问服务器上的大量程序和信息。 FTP 的主要作用，就是让用户连接上一个远程计算机（这些计算机上运行着 FTP 服务器程序）查看远程计算机有哪些文件，然后把文件从远程计算机上拷贝到本地计算机。或把本地计算机的文件送到远程计算机去。FTP 用得比 NFS 更多。</p>
<h2 id="安装pure-ftpd"><a href="#安装pure-ftpd" class="headerlink" title="安装pure-ftpd"></a>安装pure-ftpd</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在 centos 或者 redhat linux 上有自带的 ftp 软件叫做 vsftp ，但 pure-ftpd 比 vsftp 配置起来更加灵活。</p>
<h3 id="1-下载软件"><a href="#1-下载软件" class="headerlink" title="1.下载软件"></a>1.下载软件</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<a href="http://www.pureftpd.org/project/pure-ftpd" target="_blank" rel="external">pure-ftpd 官网</a> </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># cd /usr/local/src</span></div><div class="line">[root@192 src]<span class="comment"># wget http://download.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.42.tar.bz2</span></div></pre></td></tr></table></figure>
<h3 id="2-安装-pure-ftpd"><a href="#2-安装-pure-ftpd" class="headerlink" title="2.安装 pure-ftpd"></a>2.安装 pure-ftpd</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@192 src]<span class="comment"># tar jxvf pure-ftpd-1.0.42.tar.bz2 </span></div><div class="line">[root@192 src]<span class="comment"># cd pure-ftpd-1.0.42</span></div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">./configure \</div><div class="line">--prefix=/usr/<span class="built_in">local</span>/pureftpd \</div><div class="line">--without-inetd \</div><div class="line">--with-altlog \</div><div class="line">--with-puredb \</div><div class="line">--with-throttling \</div><div class="line">--with-peruserlimits \</div><div class="line">--with-tls</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编译报错</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">configure: error: <span class="keyword">in</span> `/usr/<span class="built_in">local</span>/src/pure-ftpd-1.0.42<span class="string">':</span></div><div class="line"><span class="string">configure: error: no acceptable C compiler found in $PATH</span></div><div class="line"><span class="string">See `config.log'</span> <span class="keyword">for</span> more details</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解决办法：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">yum install -y gcc</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编译报错：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">configure: error: OpenSSL headers not found.</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解决办法：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">yum install -y openssl-devel</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/pureftp%E9%83%A8%E7%BD%B2%E5%92%8C%E4%BC%98%E5%8C%96/01.png?raw=true" alt=""></figure></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 pure-ftpd-1.0.42]<span class="comment"># make &amp;&amp; make install</span></div></pre></td></tr></table></figure>
<h3 id="3-配置-pure-ftpd"><a href="#3-配置-pure-ftpd" class="headerlink" title="3.配置 pure-ftpd"></a>3.配置 pure-ftpd</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[root@192 pure-ftpd-1.0.42]<span class="comment"># cd configuration-file/</span></div><div class="line">[root@192 configuration-file]<span class="comment"># mkdir -p /usr/local/pureftpd/etc/</span></div><div class="line">[root@192 configuration-file]<span class="comment"># cp pure-ftpd.conf /usr/local/pureftpd/etc/pure-ftpd.conf</span></div><div class="line">[root@192 configuration-file]<span class="comment"># cp pure-config.pl /usr/local/pureftpd/sbin/pure-config.pl</span></div><div class="line">[root@192 configuration-file]<span class="comment"># chmod 755 /usr/local/pureftpd/sbin/pure-config.pl</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在启动 pure-ftpd 之前需要先修改配置文件，配置文件为 /usr/local/pureftpd/etc/pure-ftpd.conf，把自带配置删除</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@192 configuration-file]<span class="comment"># &gt; /usr/local/pureftpd/etc/pure-ftpd.conf </span></div><div class="line">[root@192 configuration-file]<span class="comment"># vim /usr/local/pureftpd/etc/pure-ftpd.conf</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;加入内容：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div></pre></td><td class="code"><pre><div class="line">ChrootEveryone             yes</div><div class="line">BrokenClientsCompatibility no</div><div class="line">MaxClientsNumber           50</div><div class="line">Daemonize                  yes</div><div class="line">MaxClientsPerIP            8</div><div class="line">VerboseLog                 no</div><div class="line">DisplayDotFiles            yes</div><div class="line">AnonymousOnly              no</div><div class="line">NoAnonymous                no</div><div class="line">SyslogFacility             ftp</div><div class="line">DontResolve                yes</div><div class="line">MaxIdleTime                15</div><div class="line">PureDB                     /usr/<span class="built_in">local</span>/pureftpd/etc/pureftpd.pdb</div><div class="line">LimitRecursion             3136 8</div><div class="line">AnonymousCanCreateDirs     no</div><div class="line">MaxLoad                    4</div><div class="line">AntiWarez                  yes</div><div class="line">Umask                      133:022</div><div class="line">MinUID                     100</div><div class="line">AllowUserFXP               no</div><div class="line">AllowAnonymousFXP          no</div><div class="line">ProhibitDotFilesWrite      no</div><div class="line">ProhibitDotFilesRead       no</div><div class="line">AutoRename                 no</div><div class="line">AnonymousCantUpload        no</div><div class="line">PIDFile                    /usr/<span class="built_in">local</span>/pureftpd/var/run/pure-ftpd.pid</div><div class="line">MaxDiskUsage               99</div><div class="line">CustomerProof              yes</div></pre></td></tr></table></figure>
<h3 id="4-启动-pure-ftpd"><a href="#4-启动-pure-ftpd" class="headerlink" title="4.启动 pure-ftpd"></a>4.启动 pure-ftpd</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@192 configuration-file]<span class="comment"># cd /usr/local/pureftpd/</span></div><div class="line">[root@192 pureftpd]<span class="comment"># ./sbin/pure-config.pl ./etc/pure-ftpd.conf</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/pureftp%E9%83%A8%E7%BD%B2%E5%92%8C%E4%BC%98%E5%8C%96/02.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果启动成功，会显示一行长长的以 Running 开头的信息，否则那就是错误信息。重启会比较麻烦一些，重启可以使用下面的命令来实现：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@192 pureftpd]<span class="comment"># killall pure-ftpd</span></div><div class="line">[root@192 pureftpd]<span class="comment"># cd /usr/local/pureftpd/;./sbin/pure-config.pl ./etc/pure-ftpd.conf</span></div></pre></td></tr></table></figure>
<h3 id="5-建立帐号"><a href="#5-建立帐号" class="headerlink" title="5.建立帐号"></a>5.建立帐号</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;pure-ftpd 使用的帐号并非 linux 系统帐号，而是虚拟帐号。因为这样做比较安全。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># mkdir -p /data/www/</span></div><div class="line">[root@192 ~]<span class="comment"># useradd www</span></div><div class="line">[root@192 ~]<span class="comment"># chown -R www:www /data/www/</span></div><div class="line">[root@192 ~]<span class="comment"># /usr/local/pureftpd/bin/pure-pw useradd ftp_user1 -uwww -d /data/www/</span></div><div class="line">Password: </div><div class="line">Enter it again:</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;其中，-u 将虚拟用户 ftp_user1 与系统用户 www 关联在一起，也就是说使用 ftp_user1 帐号登录 ftp 后，会以 www 的身份来读取文件或下载文件。 -d 后边的目录为 ftp_user1 账户的家目录，这样可以使 ftp_user1 只能访问其家目录 /data/www/ 。到这里还有最关键的一部，就是创建用户信息数据库文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># /usr/local/pureftpd/bin/pure-pw mkdb</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;pure-pw 还可以列出当前的 ftp 帐号，当然也可以删除某个帐号。再创建一个帐号：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># /usr/local/pureftpd/bin/pure-pw useradd ftp_user2 -uwww -d /tmp/</span></div><div class="line">Password: </div><div class="line">Enter it again: </div><div class="line">[root@192 ~]<span class="comment"># /usr/local/pureftpd/bin/pure-pw mkdb</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;列出当前帐号：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># /usr/local/pureftpd/bin/pure-pw list</span></div><div class="line">ftp_user1 /data/www/./ </div><div class="line">ftp_user2 /tmp/./</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;删除帐号的命令为：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># /usr/local/pureftpd/bin/pure-pw userdel ftp_user2</span></div></pre></td></tr></table></figure>
<h3 id="6-测试-pure-ftpd"><a href="#6-测试-pure-ftpd" class="headerlink" title="6.测试 pure-ftpd"></a>6.测试 pure-ftpd</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;测试需要的工具叫做 lftp ，先安装</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># yum install -y lftp</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;测试：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># touch /data/www/123.txt</span></div><div class="line">[root@192 ~]<span class="comment"># lftp ftp_user1@127.0.0.1</span></div></pre></td></tr></table></figure>
<p> &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;注：登录以后可以用 get 下载，put 上传。也可以用 ftp + ip 登录。</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/pureftp%E9%83%A8%E7%BD%B2%E5%92%8C%E4%BC%98%E5%8C%96/03.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;登录后，使用 ls 命令可以列出当前目录都有什么软件。使用 lftp 工具是为了方便在 linux 系统里测试。最好的测试方法是，在 windows 机器里安装个 ftp 客户端软件（推荐 filezilla-client），然后去远程连接测试。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;下面使用 yum 安装 pure-ftpd 的方法。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># yum install -y epel-release expect</span></div><div class="line">[root@192 ~]<span class="comment"># yum install -y pure-ftpd</span></div><div class="line">[root@192 ~]<span class="comment"># curl http://www.apelearn.com/study_v2/.pf.c &gt; /etc/pure-ftpd/pure-ftpd.conf</span></div><div class="line">[root@192 ~]<span class="comment"># user='mkpasswd -l 5 -s 0 -d 0 -C 0'</span></div><div class="line">[root@192 ~]<span class="comment"># pass='mkpasswd -s 0'</span></div><div class="line">[root@192 ~]<span class="comment"># echo $user $pass &gt; /tmp/ftp.pass</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;创建 ftp 服务的目录</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># mkdir -p /data/ftp</span></div><div class="line">[root@192 ~]<span class="comment"># echo -e "$pass\n$pass"|pure-pw useradd $user -u apache -d /data/ftp/</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;创建密码文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># pure-pw mkdb</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;列出用户</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># pure-pw list</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;删除帐号</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># pure-pw userdel $user</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;启动服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># /etc/init.d/pure-ftpd start</span></div></pre></td></tr></table></figure>

	

	
		<span class="different-posts"><a href="/2017/10/12/FTP/1. pureftp部署和优化/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
